package com.bangdream.michelia.view.adapter.viewpage;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.bangdream.michelia.entity.LearningStateBean;
import com.bangdream.michelia.view.fragment.main.home.HomeCoursesInfoNmuber;
import com.bangdream.michelia.view.fragment.main.home.HomeExamNmuber;
import com.bangdream.michelia.view.fragment.main.home.HomeTrainNmuber;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
 * @date on 2018/6/19 22:17
 * @email 909732184@qq.com
 * 首页显示用户信息的适配器
 */
public class InfoPageAdapter extends FragmentStatePagerAdapter {

    private LearningStateBean data;

    public InfoPageAdapter(FragmentManager fm, Context context, LearningStateBean value) {
        super(fm);
        this.data = value;
    }

    @Override
    public int getCount() {
        return 3;
    }

    @Override
    public Fragment getItem(int position) {
        switch (position) {
            case 0:
                final Bundle bundle = new Bundle();
                List<String> unfinished = data.getExam_unfinished();
                List<String> finished = data.getExam_finished();
                int size1=0;
                int size2=0;
                if(unfinished!=null) {
                    unfinished.removeAll(Collections.singleton(""));
                    size1=unfinished.size();
                }
                if(finished!=null){
                    finished.removeAll(Collections.singleton(""));
                    size2=finished.size();
                }
                bundle.putString("numberList", size2 + "," + size1);
                HomeExamNmuber fragment = new HomeExamNmuber();
                fragment.setArguments(bundle);
                return fragment;
            case 1:
                final Bundle bundle2 = new Bundle();
                List<String> course_topay = data.getCourse_topay();//待支付
                List<String> course_finished = data.getCourse_finished();//已完成
                List<String> course_unfinished = data.getCourse_unfinished();//待学习
                int size3=0;
                int size4=0;
                int size5=0;
                if(course_topay!=null){
                    course_topay.removeAll(Collections.singleton(""));
                    size3=course_topay.size();
                }
                if(course_finished!=null){
                    course_finished.removeAll(Collections.singleton(""));
                    size4=course_finished.size();
                }
                if(course_unfinished!=null){
                    course_unfinished.removeAll(Collections.singleton(""));
                    size5=course_unfinished.size();
                }
                bundle2.putString("numberList", size4 + "," + size5+"," + size3);
                HomeCoursesInfoNmuber fragment2 = new HomeCoursesInfoNmuber();
                fragment2.setArguments(bundle2);
                return fragment2;
            case 2:
                int size6=0;
                int size7=0;
                final Bundle bundle3 = new Bundle();
                List<String> plan_completed = data.getPlan_completed();
                List<String> plan_tbd = data.getPlan_TBD();
                if(plan_completed!=null){
                    plan_completed.removeAll(Collections.singleton(""));
                    size6=plan_completed.size();
                }
                if(plan_tbd!=null){
                    plan_tbd.removeAll(Collections.singleton(""));
                    size7=plan_tbd.size();
                }
                bundle3.putString("numberList", size6 + "," + size7);
                HomeTrainNmuber fragment3 = new HomeTrainNmuber();
                fragment3.setArguments(bundle3);
                return fragment3;
            default:
                return null;
        }
    }


}